#include <iostream>
#include "inetapi.hpp"
#include "protocol.hpp"

namespace tcp
{
using namespace proto;
const std::string ops = "+-*/%";

class tcp_client : public inet::tcp::client
{
public:
    tcp_client(const std::string& sip, uint16_t sport) : client(sip, sport)
    {}

    ~tcp_client()
    {}

    void init()
    {}

    void start()
    {
        while (true)
        {
            int x = rand() % 10;
            int y = rand() % 10;
            char op = ops[rand() % ops.size()];

            request req(x, op, y);
            std::string reqstr = req.serialize();
            send(reqstr);

            std::string rspstr = response::recvpack(_sock);

            response rsp;
            rsp.deserialize(rspstr);

            if (rsp._st == 0) std::cout << "ok: " << rsp._res << std::endl;
            else              std::cout << "error" << std::endl;
        }
    }

private:

};

}
